import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);
var userMsg = JSON.parse(localStorage.getItem('userMsg') || '[]')
const store = new Vuex.Store({
   state:{
      userMsg:userMsg,//用户信息的保存
      ballStatus:false,//加载小球动画的显示与隐藏
      keepAlive:['home','sources'],//设置缓存对象
   },
   mutations:{
      //保存用户信息
       getUserMsg(state,userMsg){
          state.userMsg = JSON.parse(userMsg)
          localStorage.setItem('userMsg',userMsg)
       },
       //改变小球显示与隐藏状态
       changeStatusBall(state,status){
         state.ballStatus = status
       },
       //清空用户信息
       clearUserMsg(){
         localStorage.removeItem('userMsg')
       },
       setKeepAlive(state,keepAlive){
         state.keepAlive = keepAlive
       }
   },
   getters:{
       keepAlive:state => state.keepAlive
   }
})

export default store;